<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
    <script type="text/javascript">
    	$(function(){
    		$('#to').click(function(){
    			$('#str').val($('#js').val().replace(/\\/g, '\\\\').replace(/\'/g,'\\\'').replace(/\"/g, '\\\"'));
    		});
    	});
    </script>
	<style type="text/css">
		body{
			margin: 5%;
		}
		textarea{
			width: 100%;
			height: 200px;
		}
		button{
			width:100%;
			height: 40px;
			margin: 10px 0;
			font-size: 14px;
		}
	</style>
</head>
<body>
<textarea id='js'></textarea>
<button id='to'>转成字符串↓↓↓</button>
<textarea id='str'></textarea>
</body>
</html>